﻿#region Imports
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using CommonUtilities.Extensions;
using CommonUtilities.Messages;
using OneStopProgrammingMatrix.ViewModels;
#endregion

namespace OneStopProgrammingMatrix.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class OSPMatrix : Window
    {
        #region Declarations
        MatrixViewModel dataContext;
        #endregion

        #region Properties

        #endregion

        #region Constructors
        public OSPMatrix()
        {
            InitializeComponent();

            lstLinks.Items.Clear();
            orgForeground = txtSearch.Foreground;
            align = txtSearch.TextAlignment;
            txtSearch_LostFocus(null, null);

            dataContext = new MatrixViewModel() { BindedWindow = this };
            this.Loaded += (s, e) => { this.DataContext = dataContext; };
        }
        #endregion

        #region Events
        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Escape:
                    if (MessageBoxUtil.Show(Debugger.IsAttached, Properties.Resources.Msg_ApplicationExit, Properties.Resources.App_Confirmation, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        Application.Current.Shutdown();
                    break;

                case Key.F:
                    if (!txtSearch.IsFocused)
                    { txtSearch.Focus(); e.Handled = true; }
                    break;

                default:
                    break;
            }
        }
        #endregion




        // WIP

        string hintText = Properties.Resources.Hint_Search;
        Brush orgForeground;
        TextAlignment align;

        #region Events
        private void txtSearch_GotFocus(object sender, RoutedEventArgs e)
        {
            if (txtSearch.Text.IsNullOrEmpty() | txtSearch.Text == hintText)
            { txtSearch.Clear(); txtSearch.Foreground = orgForeground; txtSearch.TextAlignment = align; }
        }

        private void txtSearch_LostFocus(object sender, RoutedEventArgs e)
        {
            if (txtSearch.Text.IsNullOrEmpty() | txtSearch.Text == hintText)
            { txtSearch.Text = hintText; txtSearch.Foreground = Brushes.Gray; txtSearch.TextAlignment = TextAlignment.Center; }
        }

        private void brdTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void chkDefaultFirst_CheckedChanged(object sender, RoutedEventArgs e)
        {
            chkDefaultFirst.Content = "Empty at " + (chkDefaultFirst.IsChecked.Value ? "first" : "last");
        }
        #endregion
    }
}
